
#include "animationlabel.h"

#include <QDebug>

AnimationLabel::AnimationLabel(int joint, int type, float start, float stop, int priority)
{
	jointNumber = joint;
	jointType = type;
	startValue = start;
	stopValue = stop;
	priorityValue = priority;
	
	setAutoFillBackground(true);
	
	paletteOn = new QPalette();
	paletteOn->setColor(QPalette::Window, QColor(Qt::green));
	
	paletteOff = new QPalette();
	paletteOff->setColor(QPalette::Window, QColor(Qt::red));
		
	switch(jointType)
	{
	case 0:
		jointLabel = new QLabel(QString("Joint:  %1").arg(joint));
		break;
	case 1:
		jointLabel = new QLabel(QString("Revolute:  %1").arg(joint));
		break;
	case 2:
		jointLabel = new QLabel(QString("Prismatic:  %1").arg(joint));
		break;
	case 3:
		jointLabel = new QLabel(QString("Gripper:  %1").arg(joint));
		break;
	}
		
	currentLabel = new QLabel(QString("%1").arg(start));
	
	setPalette(*paletteOff);
	
	layout = new QHBoxLayout(this);
	layout->addWidget(jointLabel);
	layout->addWidget(currentLabel);
	
}

void AnimationLabel::playing(int priority)
{
// 	qDebug()<<"AnimationLabel changed priority to"<<priority<<"from"<<priorityValue<<"widget is"<<jointType;
	if (priority == priorityValue)
	{
		setPalette(*paletteOn);
		update();
	}	
	else
	{
		setPalette(*paletteOff);
		update();
	}
}

void AnimationLabel::setValue(float value)
{
	currentLabel->setText(QString("%1").arg(value));
}